/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package services;

import services.interfaces.IMessageService;
import java.util.ArrayList;
import java.util.List;
import models.Messages;
import models.Users;

/**
 *
 * @author amega
 */
public class MessageServiceImpl implements IMessageService  {


    
    @Override
    public List<Messages> getNewUserMessage(Users user) {
        List<Messages> userMessage = new ArrayList<Messages>();
        for (Messages item: user.getListMessage()) {
            if (item.isRead() == false)
                userMessage.add(item);
        }
        return userMessage;
    }


    @Override
    public void setMessageRead(Messages message) {     
        message.setMessageRead(true);
        //
    }

    @Override
    public void sendMessageToUser(Users from, Users to, Messages message) {
        message.setUserTo(to);
        message.setUserFrom(from);
        message.setMessageRead(false);
        from.addMessage(message);
        to.addMessage(message);
    }

    @Override
    public void delUserMessages(Users user) {
        user.getListMessage().removeAll(user.getListMessage());  
    }
    
}
